package cn.ranko.site.action;

import cn.ranko.bean.easyui.DataGrid;
import cn.ranko.bean.easyui.DataGridParam;
import cn.ranko.bean.easyui.Messager;
import cn.ranko.bean.easyui.TreeNode;
import cn.ranko.site.model.SysPermissions;
import cn.ranko.site.model.SysUsers;
import cn.ranko.site.service.SysPermissionsService;
import cn.ranko.utils.ErrorCode;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by ZJ08 on 2016/7/28.
 *
 * 权限管理
 *
 */
@Controller
@RequestMapping("/site-permissions")
public class SysPermissionsAction {

    @Autowired
    SysPermissionsService sysPermissionsService;

    @RequiresPermissions("site-permissions:view")
    @RequestMapping(value = "index.action",method = RequestMethod.GET)
    public String syspermissions() {
        return "site/permissions/index";
    }

    @RequiresPermissions("site-permissions:view")
    @ResponseBody
    @RequestMapping(value = "loadList.action",method = RequestMethod.GET)
    public DataGrid loadList(){
        List<Map>  permissions = sysPermissionsService.selectAll();

        DataGrid dataGrid = new DataGrid();
        dataGrid.setRows(permissions);
        dataGrid.setTotal(permissions.size());

        return dataGrid;
    }

    /**
     * 权限添加、界面显示
     * @return
     */
    @RequiresPermissions("site-permissions:add")
    @RequestMapping(value = "showadd.action",method = RequestMethod.GET)
    public String showadd(){
        return "site/menus/showedit";
    }

    /**
     * 权限编辑、界面显示
     * @return
     */
    @RequiresPermissions("site-permissions:edit")
    @RequestMapping(value = "showedit.action",method = RequestMethod.GET)
    public String showedit(){
        return "site/menus/showedit";
    }

    /**
     * 权限保存操作
     * @return
     */
    @RequiresPermissions(value = {"site-permissions:edit","site-permissions:add"},logical = Logical.OR)
    @ResponseBody
    @RequestMapping(value = "save.action",method = RequestMethod.POST)
    public String save(){
        return "";
    }

    /**
     * 权限删除操作
     *
     * @param ids
     * @return
     */
    @RequiresPermissions("site-permissions:delete")
    @RequestMapping(value = "delete.action",method = RequestMethod.GET)
    @ResponseBody
    public Messager delete(String ids){
        return new Messager(ErrorCode.UPDATE_SUCCESS);
    }


}
